package com.mt.demo.controller;

import com.mt.demo.domain.AjaxResult;
import com.mt.demo.manager.MeetingRoomManager;
import com.mt.demo.manager.MeetingUserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/meeting/stats")
public class MeetingStatsController extends BaseController {

    @Autowired
    private MeetingRoomManager meetingRoomManager;

    @Autowired
    private MeetingUserManager meetingUserManager;

    /**
     * 获取会议在线用户数
     */
    @GetMapping("/online-count/{meetingId}")
    public AjaxResult getOnlineCount(@PathVariable String meetingId) {
        int onlineCount = meetingRoomManager.getRoomOnlineCount(meetingId);
        return AjaxResult.success(onlineCount);
    }

    /**
     * 获取会议详细统计信息
     */
    @GetMapping("/detail/{meetingId}")
    public AjaxResult getMeetingStats(@PathVariable String meetingId) {
        Map<String, Object> stats = new HashMap<>();
        stats.put("onlineCount", meetingRoomManager.getRoomOnlineCount(meetingId));
        stats.put("onlineUsers", meetingUserManager.getOnlineUsers(meetingId));
        stats.put("screenSharingUser", meetingRoomManager.getScreenSharingUser(meetingId));
        
        return AjaxResult.success(stats);
    }

    /**
     * 获取所有会议的统计信息
     */
    @GetMapping("/all")
    public AjaxResult getAllMeetingStats() {
        // 这里可以实现获取所有活跃会议的统计信息
        // 由于需要遍历所有房间，实际实现时需要在MeetingRoomManager中添加相应方法
        return AjaxResult.success("功能开发中");
    }

    /**
     * 检查用户是否在线
     */
    @GetMapping("/user-online/{meetingId}/{userId}")
    public AjaxResult isUserOnline(@PathVariable String meetingId, @PathVariable String userId) {
        boolean isOnline = meetingUserManager.isUserOnline(meetingId, userId);
        return AjaxResult.success(isOnline);
    }
}
